package com.example.musicplayer.calculator;

import com.example.musicplayer.MusicPlayerApplication;
import com.example.musicplayer.R;

public class CalculateException extends Exception {
    public static final int ERROR = 0;
    public static final int INVALID_CHARACTER = 1;
    public static final int INVALID_NUMBER = 2;
    public static final int INVALID_BRACKET = 3;
    public static final int INVALID_OPERATOR = 4;
    public static final int INVALID_FACTORIAL_NUMBER = 5;
    public static final int INVALID_DIVIDE_ZERO = 6;
    public static final int CALCULATE_ERROR = 7;

    public CalculateException() {
        this(ERROR);
    }

    public CalculateException(int type) {
        super(getExceptionMessage(type));
    }

    private static String getExceptionMessage(int type) {
        int messageId;
        switch (type) {
            case INVALID_CHARACTER:
                messageId = R.string.invalid_character;
                break;
            case INVALID_NUMBER:
                messageId = R.string.invalid_number;
                break;
            case INVALID_BRACKET:
                messageId = R.string.invalid_bracket;
                break;
            case INVALID_OPERATOR:
                messageId = R.string.invalid_operator;
                break;
            case INVALID_FACTORIAL_NUMBER:
                messageId = R.string.invalid_factorial_number;
                break;
            case INVALID_DIVIDE_ZERO:
                messageId = R.string.invalid_divide_zero;
                break;
            case CALCULATE_ERROR:
                messageId = R.string.calculate_error;
                break;
            case ERROR:
            default:
                messageId = R.string.unknown_error;
                break;
        }
        return MusicPlayerApplication.getInstance().getString(messageId);
    }
}